package com.wm.stringbuffer;

import java.util.Scanner;

public class Product {
    public static void main(String[] args) {
        System.out.println("*************欢迎进入批发商城***************");
        System.out.println("编号\t\t商品\t\t价格");
        String[] strings = new String[]{"电风扇","洗衣机","电视机","冰箱","空调机"};
        double[] doubles = new double[]{123.23,4500.0,8800.9,5000.88,4456.0};
        for (int i = 0; i <strings.length ; i++) {
            System.out.println((i+1) + "\t\t" + strings[i] + "\t" + doubles[i]);
        }
        System.out.println("*******************************************");
        Scanner input = new Scanner(System.in);
        System.out.print("请输入您批发的商品编号：");
        int id = input.nextInt();
        System.out.print("请输入您批发数量：");
        int num = input.nextInt();
        System.out.println("您需要付款:"+transform(doubles[id-1]*num) + "元");
    }
    public static StringBuffer transform(double num) {
        StringBuffer ch = new StringBuffer(String.valueOf(num));
        for(int i = ch.lastIndexOf(".")-3;i>0;i = i-3) {
            ch.insert(i, ",");
        }
        return ch;
    }
}
